/*
 * Copyright 2013 floreysoft GmbH (www.floreysoft.net)
 *
 *
 * Licensed under the Apache License, Version 2.0 (the "License"); you may not
 * use this file except in compliance with the License. You may obtain a copy of
 * the License at
 *
 * http://www.apache.org/licenses/LICENSE-2.0
 *
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
 * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
 * License for the specific language governing permissions and limitations under
 * the License.
 */
package com.floreysoft.gwt.drive.client.utils;

import com.google.api.gwt.client.GoogleApiLoader;
import com.google.gwt.core.client.Callback;
import com.google.gwt.core.shared.GWT;

/**
 * Loads the google drive API
 *
 */
public class DriveLoader {
	public static final String DRIVE_API = "drive";
	public static String DRIVE_VERSION = "v2";

	/**
	 * Loads the realtime api with the given version
	 * 
	 * @param runnable
	 *            The callback
	 */
	public static void loadApi(String apiKey, final Runnable runnable) {
		GoogleApiLoader.get().load(new Callback<Void, Exception>() {
			
			@Override
			public void onSuccess(Void result) {
				runnable.run();
			}
			
			@Override
			public void onFailure(Exception reason) {
			}
		});
	}
	
	/**
	 * Loads the drive api 
	 * 
	 * @param version
	 *            The picker version
	 * @param runnable
	 *            The callback
	 */
	public static void loadDriveApi(final Runnable runnable) {
		GoogleApiLoader.get().loadDriveApi(new Callback<Void, Exception>() {

			@Override
			public void onFailure(Exception reason) {
				GWT.log("drive api nicht geladen");
				
			}

			@Override
			public void onSuccess(Void result) {
				runnable.run();
				
			}
		});
	}

	
}
